<template>
  <div class="login">
    <div class="con">
      <h3 class="text-center">登录</h3>
      <el-input v-model="user.username" placeholder="请输入用户名" clearable></el-input>
      <el-input v-model="user.password" placeholder="请输入密码" clearable show-password></el-input>
      <div class="text-center">
        <el-button type="primary" @click="login">登录</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import {requserlogin} from "../../http/api";
import { mapActions } from "vuex";
import { successAlert } from "../../utils/alert";
export default {
    data(){
        return {
            user:{
              username:'',
              password:''
            }
        }
    },
    methods:{
      ...mapActions({
        set_userInfo:'set_userInfo'
      }),
      login(){
        requserlogin(this.user).then(res=>{
          if(res.data.code===200){
            //弹成功
            successAlert(res.data.msg);
            // 存储用户信息
            this.set_userInfo(res.data.list);
            //跳转页面
            this.$router.push("/")
          }
        }).catch(err=>{
          console.log(err);
        })
      }
    }
}
</script>

<style lang="less" scoped>
@import "../../less/index.less";
.login {
  width: 100vw;
  height: 100vh;
  position: relative;
  background: linear-gradient(to right, @bg-light, @bg-deep);
  .con {
    width: 300px;
    background: #fff;
    padding: @padding20;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    border-radius: @padding10;
    h3,.el-input{
        margin-bottom: @padding10;
    }
  }
}
</style>
